<extend name="Public/base"/>

<block name="body">
    <!-- 导入css样式 -->
    <link rel="stylesheet" href="__PUBLIC__/Admin/css/mymember.css">
    <div class="main-title">
        <h2><present name="data">[ {$data.title} ] 子</present>用户列表</h2>
    </div>
    <div class="cf">
        <div class="fl">
            <button class="btn ajax-post" url="{:U('Goods/setStatus',array('status'=>1,'model'=>'user'))}" target-form="ids">启 用</button>
            <button class="btn ajax-post" url="{:U('Goods/setStatus',array('status'=>0,'model'=>'user'))}" target-form="ids">禁 用</button>
            <button class="btn ajax-post confirm" url="{:U('Goods/setStatus',array('status'=>-1,'model'=>'user'))}" target-form="ids">删 除</button>
        </div>
        <p style="float:left;margin-bottom:10px;">
            <a href="{:U('MyMember/Userlist',array('sort'=>'asc'))}" class="btn">ID正向排序</a>
            <a href="{:U('MyMember/Userlist',array('sort'=>'desc'))}" class="btn">ID逆向排序</a>
        </p>

        <!-- 高级搜索 -->
        <div class="search-form fr cf">
            <div class="sleft">
                <input type="text" name="username" class="search-input" value="{:I('username')}" placeholder="请输会员ID或者会员账号">
                <a class="sch-btn" href="javascript:;" id="search" url="{:U('MyMember/userlist')}"><i class="btn-search"></i></a>
            </div>
        </div>
    </div>

    <div class="data-table table-striped">
            <table>
                <thead>
                    <tr>
                        <th class="row-selected row-selected">
                            <input class="checkbox check-all" type="checkbox">
                        </th>
                        <th>ID</th>
                        <th>账号</th>
                        <th>密码</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
				<notempty name="list">
                <volist name="list" id="val">
                    <tr>
                        <td><input class="ids row-selected" type="checkbox" name="ids[]" value="{$val.user_id}"></td>
                        <td>{$val.user_id}</td>
                        <td><a href="{:U('MyMemberDetail/userlist?user_id='.$val['user_id'])}">{$val.username}</a></td>
                        <td>{$val.password}</td>
                        <td>{$val.status}</td>
                        <td>
                            <a class='status' sign="{$val.status}" index="{$val.user_id}" href="">启用</a>
                        </td>
                    </tr>
                </volist>
				<else/>
				<td colspan="10" class="text-center"> aOh! 暂时还没有内容! </td>
				</notempty>
                </tbody>
            </table>
        <div class="page">
            {$_page}
        </div>
    </div>
</block>

<block name="script">
  <script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>
    <script type="text/javascript">

        $(function() {
            //搜索功能
            $("#search").click(function() {
                var url = $(this).attr('url');
                var query = $('.search-form').find('input').serialize();
                query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
                query = query.replace(/^&/g, '');
                if (url.indexOf('?') > 0) {
                    url += '&' + query;
                } else {
                    url += '?' + query;
                }
                window.location.href = url;
            });
            //回车搜索
            $(".search-input").keyup(function(e) {
                if (e.keyCode === 13) {
                    $("#search").click();
                    return false;
                }
            });
            //导航高亮
            highlight_subnav('{:U('MyMember/Userlist')}');
            //点击排序
        	$('.list_sort').click(function(){
        		var url = $(this).attr('url');
        		var ids = $('.ids:checked');
        		var param = '';
        		if(ids.length > 0){
        			var str = new Array();
        			ids.each(function(){
        				str.push($(this).val());
        			});
        			param = str.join(',');
        		}

        		if(url != undefined && url != ''){
        			window.location.href = url + '/ids/' + param;
        		}
        	});
        });

        //状态操作
        $(function(){
          //获取目标当前的状态，同时进行遍历
          var mystatus = $('.status');
          var num = mystatus.length;
          for (var i=0;i<num;i++) {
            // 对当前的状态获取之后，设置当前状态的操作
            if(mystatus.eq(i).attr('sign')=='启用'){
                mystatus.eq(i).html('禁用');
            }
            if(mystatus.eq(i).attr('sign')=='禁用'){
                mystatus.eq(i).html('启用');
            }
          }
        });

        // 绑定每个按钮的点击事件
        $('.status').each(function(){
          $(this).click(function(){
              // 获取当前目标所绑定的的索引，即本行的user_id
              var user_id = $(this).attr('index');
              // 运用ajax中的post方法传递参数，获取本行的user_id
              $.get("{:U('MyMember/change')}" , {user_id:user_id} , function(){

              } );
              // 点击修改目标的属性，同属修改HTML标签里面的显示内容
              var mystatus=$(this).parent().prev();
              var status=$(this).attr('sign');
              if(status=='启用'){
                  $(this).html('启用');
                  $(this).attr('sign','禁用');
                  mystatus.html('禁用');
              }
              if(status=='禁用'){
                  $(this).html('禁用');
                  $(this).attr('sign','启用');
                  mystatus.html('启用');
              }
              // 取消里面的默认行为
              return false;
          });
        });


        // // 设置右边的状态按钮
        // $('#trr td[sta=sta]').each(function(i){
        //   var str = $(this).html();
        //   if (str == '禁用') {
        //     $(this).next().children().eq(1).html('启用');
        //   }else{
        //     $(this).next().children().eq(1).html('禁用');
        //   }
        //
        // })



    </script>
</block>
